<include file="../Public/header" />

    <link href="__PUBLIC__/themes/blue/layout.css" rel="stylesheet" type="text/css" />
    
<script type="text/javascript" src="__PUBLIC__/js/tbox/tbox.js" ></script>
<script type="text/javascript" src="__PUBLIC__/js/admin.js" ></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-admin-box.js"></script>

<script>
	// tbox用常量
	var THEME = "__THEME__";
	var APP    = "__APP__";
	var URL    = "__URL__";
	var PUBLIC = "../Public";
	var SITE_URL = "{*SITE_URL}";

	//验证限制条件的合法性
	function checkLimit() {
		bool = /^\d+$/.test( $('#attach_size').val() );
		if(bool) {
			return true;
		}else {
			$.tbox.no('附件大小必须为大于0的整数～',"提示");
			setTimeout("$.tbox.close()",1500);
			return false;
		}
	}
</script>

<body>
<div id="container_s">
	<!-- 顶部tab BEGIN -->
	<div class="tab">
		<ul>
			<li><a href="{:U('admin/System/attach')}" <eq name="ACTION_NAME" value="attach">class="on"</eq>>附件管理</a></li>
			<li><a href="{:U('admin/System/attach_recycle')}" <eq name="ACTION_NAME" value="attach_recycle">class="on"</eq>>回收站</a></li>
		</ul>
	</div>
	<!-- 顶部tab END -->

	<!-- 设置附件的限制条件 BEGIN -->
	<form action="{:U('admin/System/doAttachLimit')}" method="post" onsubmit="return checkLimit();">
		<table class="tableborder" width="100%" id="attach_limit">
			<tbody>
				<tr class="top">
					<td class="border" colspan="2"></td>
				</tr>
				<tr onclick="$('#attach_limit .cell').toggle();">
					<th class="header" colspan="2">附件的限制条件</th>
				</tr>
				<tr class="label cell">
					<th>说明</th>
					<th>设置</th>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>大小限制</b><br/><span class="smalltxt">大约0的整数；单位：兆</span>
					</td>
					<td class="altbg2"><input id="attach_size" style="width:250px;" name="attach_size" class="txt mr10" value="{$attach_size}" /><span id="tip"></span></td>
				</tr>
				<tr class="cell">
					<td class="altbg1">
						<b>类型限制</b><br/><span class="smalltxt">以英文的“,”分隔</span>
					</td>
					<td class="altbg2"><input name="attach_type" style="width:250px;" class="txt" value ="{$attach_type}" /></td>
				</tr>
				<tr class="cell">
					<td>&nbsp;</td>
					<td><input type="submit" class="button mt10 mb10" value="提交" /></td>
				</tr>
			</tbody>
		</table>
	</form>
	<!-- 设置附件的限制条件 END -->

	<!-- 搜索位 BEGIN -->
	<form  action="{:U('admin/System/attach')}" method="POST">
		<table class="tableborder" width="100%" id="search">
		  <tbody>
			<tr class="top">
			  <td class="border" colspan="2">
			  </td>
			</tr>
			<tr onclick="$('#search .cell').toggle();">
			  <th class="header" colspan="2">筛选条件</th>
			</tr>
			<tr class="label cell">
			  <th>说明</th>
			  <th>条件</th>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>用户ID</b>
				<br/>
				<span class="smalltxt">搜索该用户上传的附件</span>
			  </td>
			  <td class="altbg2">
				<input name="userId" class="txt" value="{$userId}"/> [ 注：多用户时请以英文的“,”分割 ]
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>附件标题</b>
				<br/>
				<span class="smalltxt">根据附件标题搜索,支持模糊查询</span>
			  </td>
			  <td class="altbg2"><input name="key" class="txt" value="{$key}"/> [ 注：使用“%”作为通配符 ]</td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>应用类型</b>
				<br/>
				<span class="smalltxt">只看给定应用的附件</span>
			  </td>
			  <td class="altbg2">
				<select name="attach_type">
				  <option value = "0" <empty name="attach_type">selected</empty>>无</option>
				  <volist name="attach_types" id="vo">
					<option value="{$vo}" <php>if($vo == $attach_type) echo 'selected';</php>>{$vo}</option>
				  </volist>
				</select>
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>扩展名</b>
				<br/>
				<span class="smalltxt">只看给定扩展名的附件</span>
			  </td>
			  <td class="altbg2">
				<select name="extension">
				  <option value = "0" <empty name="extension">selected</empty>>无</option>
				  <volist name="extensions" id="vo">
					<option value = "{$vo}" <php>if($vo == $extension) echo 'selected';</php>>{$vo}</option>
				  </volist>
				</select>
			  </td>
			</tr>

			<tr class="cell">
			  <td class="altbg1">
				<b>结果排序</b>
				<br/>
			  </td>
			  <td class="altbg2">
				<select name="field">
				  <option value = "mtime" <eq name="field" value="mtime">selected</eq>>按更新时间排序</option>
				  <option value = "totaldowns" <eq name="field" value="totaldowns">selected</eq>>按下载量排序</option>
				</select>

				<select name="order">
				  <option value = "DESC" <eq name="order" value="DESC">selected</eq>>降序</option>
				  <option value = "ASC" <eq name="order" value="ASC">selected</eq>>升序</option>
				</select>
	   
				<select name="limit">
				  <option value = "20" <eq name="limit" value="20">selected</eq>>每页显示20条</option>
				  <option value = "50" <eq name="limit" value="50">selected</eq>>每页显示50条</option>
				  <option value = "100" <eq name="limit" value="100">selected</eq>>每页显示100条</option>
				</select>
			  </td>
			</tr>

			<tr class="cell">
				<td>&nbsp;</td>
				<td class="pt10 pb10"><input type="submit" class="button" value="提交" /></td>
			</tr>
		  </tbody>
		</table>
	</form>
	<!-- 搜索位 END -->
	
	<!-- 正文 BEGIN -->
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder" id="checkList">
		<tbody>
			<!-- 列表标题 -->
			<tr class="top">
				<td class="border" colspan="10"></td>
			</tr>
			<tr>
				<th class="header" colspan="10"> 附件列表 </th>
			</tr>

			<!-- 列表字段 -->
			<tr class="label cell">
				<th>&nbsp;</th>
				<th>ID</th>
				<th>名称</th>
				<th>上传者</th>
				<th>更新时间</th>
				<th>下载量</th>
				<th>应用类型</th>
				<th>扩展名</th>
				<th>大小 [ 字节 ]</th>
				<th>是否私有</th>
			</tr>
			
			<!-- 列表数据 -->
			<volist name="data" id='vo'>
			<tr id="list_{$vo.id}" class="cell">
				<td><label><input type="checkbox" class="attach_admin_check" rel="0" dataId="{$vo['id']}"></label></td>
				<td>{$vo.id}</td>
				<td><a href="{:U('admin/System/downloadAttach',array('id'=>$vo['id']))}" target="_blank">{$vo.name}</a></td>
				<td><a href="{:U('space/View/index',array('uid'=>$vo['uid']))}" target="_blank">{$vo.uid|getUserName}</a></td>
				<td>{$vo.mtime}</td>
				<td>{$vo.totaldowns}</td>
				<td>{$vo.attach_type}</td>
				<td>{$vo.extension}</td>
				<td>{$vo.size}</td>
				<td><eq name="vo.private" value="1">是<else/>否</eq></td>
			</tr>
			</volist>

			<tr>
				<td class="footer" colspan="10">
					<!--
					<button type="button" onclick="checkall('checkList',true)">全选</button>
					<button type="button" onclick="checkall('checkList',false)">全不选</button>
					<button type="button" onclick="javascript:del('0','__URL__&act=deleteAsk')">删除</button>
					-->
				</td>
			</tr>

			<tr>
				<td class="footer" colspan="10">
					<div class="page mt5 alR mb20" style="float:right;">{$html}</div>
				</td>
			</tr>

			<tr class="bottom">
				<td class="border" colspan="10"></td>
			</tr>

		</tbody>
	</table>
	<!-- 正文 END -->
</div>

<!-- 前台管理 BEGIN -->
<div id="attach_admin" style="display:none;">
	<a href="javascript:void(0)" onclick="deleteAttach()">删除附件</a>
</div>
<!-- 前台管理 END -->

<!-- 页面JS BEGIN -->
<script type="text/javascript">
	//加载前台管理工具
	$(function(){
		$.fn.admin({
			prefix:'attach_',
			checkClass:'attach_admin_check',
			hiddenId:'attach_admin',
			lMinOffset:1,
			type:false,
			position:'right'
		});
	});

	//删除附件至回收站
	function deleteAttach() {		
		if(confirm('确认要将所选附件删除至回收站吗？')){
			$.post("{:U('admin/System/doDeleteAttach')}", {id:$.fn.getData('attach_')}, function(result){
				if(result == 1) {
					$.tbox.yes('删除成功',"提示");
					setTimeout("$.tbox.close()",1500);
					$.each($.fn.getData('attach_'),function(i,n){
						$("#list_"+n).remove();
					});
					$('#attach_admin_box').hide();
				}else{
					$.tbox.no('删除失败',"提示");
					setTimeout("$.tbox.close()",1500);
				}
			});
		}
	}
</script>
<!-- 页面JS END -->

</body>
</html>
